﻿using UnityEngine;

namespace Peril.Physics
{
    public class BoxShape : CollisionShape
    {

        public BoxShape(Bounds bounds, bool twoD = true):base(bounds, twoD){}


        public override CollisionResult TestCollision(ICollisionShape other)
        {
            var result = new CollisionResult();

            if(other is BoxShape)
            {
                result.Collides = BoxVsBox(this, (BoxShape)other, ref result, TwoD);
            }
            else
            {
                Debug.LogErrorFormat("Collision test not implemented: {0}-{1}", GetType(), other.GetType());
            }
            
            return result;
        }

        public static bool BoxVsBox(BoxShape a, BoxShape b, ref CollisionResult result, bool twoD)
        {
            return CollisionTest.TestAABB(a.Min, a.Max, b.Min, b.Max, ref result, twoD);
        }

    }
}
